package com.zsjt.yysapi.core.controller;


import com.zsjt.yysapi.common.model.AjaxResult;
import com.zsjt.yysapi.common.model.BaseController;
import com.zsjt.yysapi.core.param.sysUser.LoginParam;
import com.zsjt.yysapi.core.param.sysUser.RegisterParam;
import com.zsjt.yysapi.core.pojo.SysUser;
import com.zsjt.yysapi.core.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author zsq
 * @since 2021-07-09
 */
@Api(tags = "用户")
@RestController
@RequestMapping("/core/sys-user")
public class SysUserController extends BaseController {

    @Autowired
    private SysUserService sysUserService;

    /**
     * 注册
     *
     * @return
     */
    @ApiOperation("注册")
    @PostMapping("register")
    public AjaxResult register(@RequestBody RegisterParam registerParam) {
        String token = sysUserService.register(registerParam);
        AjaxResult ajaxResult = AjaxResult.success();
        ajaxResult.put("token", token);
        return ajaxResult;
    }

    /**
     * 登录
     *
     * @return
     */
    @ApiOperation("登录")
    @PostMapping("/login")
    public AjaxResult login(@RequestBody LoginParam loginParam) {
        String token = sysUserService.login(loginParam);
        AjaxResult ajaxResult = AjaxResult.success();
        ajaxResult.put("token", token);
        return ajaxResult;
    }

    /**
     * 用户信息
     *
     * @return
     */
    @ApiOperation("用户信息")
    @GetMapping("/userInfo")
    public AjaxResult userInfo() {
        return AjaxResult.success(sysUserService.userInfo());
    }
}

